package com.ctshk.sapp.finance.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.rpc.finance.dto.advance.AdvanceChargeApplyDetailDTO;
import com.ctshk.rpc.finance.dto.advance.AdvanceChargeListDTO;
import com.ctshk.rpc.finance.dto.advance.AdvancePaymentManageListDTO;
import com.ctshk.rpc.finance.dto.paidin.CurrencyAmountCountDTO;
import com.ctshk.rpc.finance.req.advance.*;
import com.ctshk.rpc.finance.service.IFinanceAdvanceChargeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 财务预付 前端控制器
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-04-08
 */
@RestController
@Api(value = "预付管理", tags = "预付管理")
@RequestMapping("/finance-advance-charge")
public class FinanceAdvanceChargeController extends BaseController {

    @DubboReference
    private IFinanceAdvanceChargeService advanceChargeService;


    @ApiOperation(value = "查询供应商", notes = "查询供应商（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "查询供应商", operDesc = "查询供应商")
    @PostMapping("/query")
    public Result<AdvanceChargeListDTO> query(@RequestBody AdvanceChargeListReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return advanceChargeService.query(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "申请", notes = "申请（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.ADD, operTitle = "申请预付", operDesc = "申请预付")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid AdvanceChargeAddApplyReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return advanceChargeService.add(req);
    }

    @ApiOperation(value = "审批", notes = "审批（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "申请预付审批", operDesc = "申请预付审批")
    @PostMapping("/approval")
    public Result approval(@RequestBody @Valid AdvanceChargeApprovalApplyReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return advanceChargeService.approval(req);
    }

    @ApiOperation(value = "申请详情", notes = "申请详情（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "申请预付详情", operDesc = "申请预付详情")
    @PostMapping("/apply-detail")
    public Result<AdvanceChargeApplyDetailDTO> applyDetail(@RequestBody @Valid AdvanceChargeApplyIdReq req) {
        return advanceChargeService.applyDetail(req);
    }

    @ApiOperation(value = "查询供应商预付款额度", notes = "申请付款-查询供应商预付款额度（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "申请付款-查询供应商预付款额度", operDesc = "申请付款-查询供应商预付款额度")
    @PostMapping("/query-quota")
    public Result<List<CurrencyAmountCountDTO>> queryQuota(@RequestBody @Valid AdvanceChargeQueryQuotaReq req) {
        return advanceChargeService.queryQuota(req);
    }

}
